package com.bilibili.lzx.api;

import com.bilibili.lzx.api.support.UserSupport;
import com.bilibili.lzx.dao.domain.JsonResponse;
import com.bilibili.lzx.dao.domain.UserMoment;
import com.bilibili.lzx.service.UserMomentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lzx
 * @date 2024/9/2 20:06
 */

@RestController
public class UserMomentApi {

    @Resource
    private UserMomentService userMomentService;

    @PostMapping("/user-moments")
    public JsonResponse<String> addUserMoments(@RequestBody UserMoment userMoment) throws Exception {
        Long currentUserId = UserSupport.getCurrentUserId();
        userMoment.setUserId(currentUserId);
        userMomentService.addUserMoments(userMoment);
        return JsonResponse.success();
    }

    @GetMapping("/user-subscribe-moments")
    public JsonResponse<List<UserMoment>> getUserSubscribeMoments()  {
        Long currentUserId = UserSupport.getCurrentUserId();
        List<UserMoment> userMoment = userMomentService.getUserSubscribeMoment(currentUserId);
        return new JsonResponse<>(userMoment);
    }

}
